package com.demo.controller;

import com.demo.pojo.Manager;
import com.demo.pojo.ResponseEntity;
import com.demo.service.ManagerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("manager")
public class ManagerController {
    @Autowired(required = false)
    ManagerService managerService;
    @RequestMapping("findOne")
    public ResponseEntity<Manager> findOne(int id){
        Manager manager = managerService.findOne(id);
        return new ResponseEntity<Manager>(200,"查询成功",manager);
    }
    @RequestMapping("findOnePage")
    public ResponseEntity<PageInfo<Manager>> findOnePage(int startPage,int pagesize){
        PageHelper.startPage(startPage,pagesize);
        List<Manager> list =managerService.findOnePage();
        PageInfo<Manager> pageInfo = new PageInfo<>(list);
        return new ResponseEntity<PageInfo<Manager>>(200,"查询成功",pageInfo);
    }
    @RequestMapping("deleteOne")
    public ResponseEntity<Integer> deleteOne(int id){
       int num = managerService.deleteOne(id);
       return new ResponseEntity<Integer>(200,"成功删除的数据"+num,num);
    }
    @RequestMapping("addOne")
    public ResponseEntity<Integer> addOne(@RequestBody Map<String,Object> map){
        int num =   managerService.addOne(map);
        return new ResponseEntity<Integer>(200,"成功添加的数据"+num,num);
    }
    @RequestMapping("changeName")
    public ResponseEntity<Integer> changeName(@RequestBody Map<String ,Object> map ){
        int num = managerService.changeName(map);
        return new ResponseEntity<Integer>(200,"成功修改的数据"+num,num);
    }

}
